<script setup lang="ts">
// 静态引入所有图片
import timeIcon from '@/assets/modeling/报警时间.png';
import typeIcon from '@/assets/modeling/报警类型.png';
import statusIcon from '@/assets/modeling/报警处置状态.png';
import levelIcon from '@/assets/modeling/报警级别.png';
import nameIcon from '@/assets/modeling/报警名称.png';
import frequencyIcon from '@/assets/modeling/上传频率.png';
import equipmentIcon from '@/assets/modeling/设备类型.png';
import wallTypeIcon from '@/assets/modeling/窨井类型.png';
import leakTypeIcon from '@/assets/modeling/气体类型.png';
import riskIcon from '@/assets/modeling/爆炸风险.png';
import speedIcon from '@/assets/modeling/扩散速度.png';
import warningLevelIcon from '@/assets/modeling/预警级别.png';
import numIcon from '@/assets/modeling/影响人数.png';

import { useIntelligentAnalyticsStore } from '@/store/modules/IntelligentAnalytics/useIntelligentAnalyticsStore';
import ModelAnalysisDialog from '../ModelAnalysisDialog/index.vue';
import { TrendCharts } from '@element-plus/icons-vue';

// 模型分析对话框控制
const showModelAnalysis = ref(false);

// 打开模型分析对话框
const openModelAnalysis = () => {
  showModelAnalysis.value = true;
};

const { riskData, modelData } = useIntelligentAnalyticsStore();
const options = {
  1: { label: '特别严重', color: '#FF0000' },
  2: { label: '严重', color: '#FFA500' },
  3: { label: '较大', color: '#FFFF00' },
  4: { label: '一般', color: '#00ffff' },
  5: { label: '无情况', color: '#808080' }
};
const selectedLabel = computed(() => {
  const level = modelData.value.warning_level;
  return options[level];
});
const infoItems = computed(() => [
  { icon: timeIcon, label: '报警时间', value: riskData.value.info.createTime, key: 'createTime' },
  { icon: typeIcon, label: '报警类型', value: riskData.value.info.alarmTypeName, key: 'alarmTypeName' },
  { icon: statusIcon, label: '报警处置状态', value: riskData.value.info.statusName, key: 'statusName' },
  { icon: levelIcon, label: '报警级别', value: riskData.value.info.alarmLevel, key: 'alarmLevel' },
  { icon: nameIcon, label: '报警名称', value: riskData.value.info.alarmTitle, key: 'alarmTitle' },
  { icon: frequencyIcon, label: '上传频率', value: riskData.value.overhaul.frequency, key: 'frequency' },
  { icon: equipmentIcon, label: '设备类型', value: riskData.value.overhaul.category, key: 'category' },
  { icon: wallTypeIcon, label: '窨井类型', value: riskData.value.overhaul.wallType, key: 'wallType' }
]);
const intelligentItems = computed(() => [
  { icon: leakTypeIcon, label: '气体类型', value: riskData.value.info.leakType, key: 'leakType' },
  { icon: riskIcon, label: '遇火爆炸风险', value: modelData.value.risk, key: 'risk' },
  {
    icon: speedIcon,
    label: '扩散速度(m/s)',
    value: modelData.value.distance_speed_list[1],
    key: 'distance_speed_list'
  },
  { icon: warningLevelIcon, label: '预警级别', value: selectedLabel.value.label, key: 'warning_level' },
  { icon: numIcon, label: '影响人数', value: modelData.value.real_time_count, key: 'real_time_count' }
]);
</script>

<template>
  <div class="event-details-container">
    <div class="basic-info">
      <div class="basic-info-title">基本信息</div>
      <div class="basic-info-main">
        <div v-for="(item, index) in infoItems" :key="index" class="info-item">
          <img :src="item.icon" :alt="item.label" class="info-icon" />
          <div class="info-content">
            <div class="info-label">{{ item.label }}</div>
            <div class="info-value" :title="item.value">
              {{ item.value || '暂无' }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="intelligent-analytics-info">
      <div class="intelligent-analytics-header">
        <div class="intelligent-analytics-info-title">智能分析</div>
        <el-button type="primary" size="small" @click="openModelAnalysis" class="analysis-btn">
          <el-icon><TrendCharts /></el-icon>
          模型分析数据
        </el-button>
      </div>
      <div class="intelligent-analytics-info-main">
        <div v-for="(item, index) in intelligentItems" :key="index" class="info-item">
          <img :src="item.icon" :alt="item.label" class="info-icon" />
          <div class="info-content">
            <div class="info-label">{{ item.label }}</div>
            <div class="info-value" :title="item.value" :style="{ color: item.key === 'warning_level' && selectedLabel.color }">
              {{ item.value || '暂无' }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="chart-box">
      <div class="chart-title">运行数据</div>
      <run-data :echartsData="riskData.value.data" :deviceInfo="riskData.value.info" />
    </div>

    <!-- 模型分析数据对话框 -->
    <ModelAnalysisDialog v-model="showModelAnalysis" />
  </div>
</template>

<style scoped lang="scss">
.event-details-container {
  width: 100%;
  height: 100%;
  gap: 1rem;
  padding: 1.25rem;
  box-sizing: border-box;

  .basic-info {
    height: 40%;

    &-title {
      font-weight: 700;
      color: #0ff;
      margin-bottom: 10px;
      font-size: 20px;
    }

    &-main {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 86%;

      .info-item {
        display: flex;
        align-items: flex-start;
        width: calc(50% - 0.5rem);
      }

      .info-icon {
        width: 2.625rem;
        height: 2.625rem;
        flex-shrink: 0;
        margin-right: 0.75rem;
      }

      .info-content {
        flex: 1;
        min-width: 0; // 防止flex布局溢出
      }

      .info-label {
        font-size: 0.875rem;
        font-weight: 500;
        color: white;
        margin-bottom: 0.5rem;
      }

      .info-value {
        font-size: 1rem;
        font-weight: 700;
        color: #00ffff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
      }
    }
  }

  .intelligent-analytics-info {
    height: 30%;

    .intelligent-analytics-header {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-bottom: 10px;
    }

    &-title {
      font-weight: 700;
      color: #0ff;
      font-size: 20px;
    }

    .analysis-btn {
      background: linear-gradient(90deg, #409eff 0%, #67c23a 100%);
      border: none;
      color: white;
      font-size: 12px;
      padding: 6px 12px;
      border-radius: 4px;
      display: flex;
      align-items: center;
      gap: 4px;
      transition: all 0.3s ease;

      &:hover {
        background: linear-gradient(90deg, #66b1ff 0%, #85ce61 100%);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(64, 158, 255, 0.3);
      }

      &:active {
        transform: translateY(0);
      }

      .el-icon {
        font-size: 14px;
      }
    }

    &-main {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 86%;

      .info-item {
        display: flex;
        align-items: flex-start;
        width: calc(50% - 0.5rem);
      }

      .info-icon {
        width: 2.625rem;
        height: 2.625rem;
        flex-shrink: 0;
        margin-right: 0.75rem;
      }

      .info-content {
        flex: 1;
        min-width: 0; // 防止flex布局溢出
      }

      .info-label {
        font-size: 0.875rem;
        font-weight: 500;
        color: white;
        margin-bottom: 0.5rem;
      }

      .info-value {
        font-size: 1rem;
        font-weight: 700;
        color: #00ffff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
      }
    }
  }

  .chart-box {
    height: 30%;

    .chart-title {
      font-weight: 700;
      color: #0ff;
      margin-bottom: 10px;
      font-size: 20px;
    }
  }
}
</style>
